﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace BlogsManage
{
    public partial class frmAdd : Form
    {
        public frmMain fm;
        DBhelp db = new DBhelp();

        public frmAdd()
        {
            InitializeComponent();
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (Ck() == true)
            {
                AddTeacher();
                this.Hide();
                this.Close();

            }
        }

        public void AddTeacher()
        {
            string sql = string.Format(@"INSERT INTO Articles
                                     VALUES('{0}','{1}','{2}','{3}') ",
                                     this.txtti_name.Text,
                                     this.txtti_gender.Text,
                                     DateTime.Now.ToString(),
                                     this.txtti_unitname.Text
                                    );


            int a = db.IDU(sql);
            if (a != 0)
            {
                MessageBox.Show("添加成功");
                fm.BindDGV();
            }
            else
            {
                MessageBox.Show("添加失败");
            }

        }
        public Boolean Ck()
        {
            if (this.txtti_name.Text == "")
            {
                MessageBox.Show("标题不能为空");
                return false;
            }
            else

            if (this.txtti_gender.Text == "")
            {
                MessageBox.Show("作者不能为空");

                return false;
            }
            else
                 if (this.txtti_unitname.Text =="")
            {
                MessageBox.Show("内容不能为空");
                return false;

            }
            else
            {
                return true;
            }
        }
    }
}
